﻿namespace OleDbDAL.Company
{
    using DBUtility;
    using IDal.Company;
    using Model.Company;
    using System;
    using System.Data;
    using System.Text;

    public class CompayAccountDetailsApp : ICompayAccountDetails
    {
        private string dbname = "Systems";

        public void Add(CompayAccountDetailsEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into T_CompayAccountDetails(");
            builder.Append("ChainNum,DetailsType,OutDetailsSource,InputDetailsSource,BuildMoney,CreateMan,NotesNum,CreateTime,IsCheck,CheckMan,CheckTime,Remark");
            builder.Append(")");
            builder.Append(" values (");
            builder.Append("" + model.ChainNum + ",");
            builder.Append("" + model.DetailsType + ",");
            builder.Append("" + model.OutDetailsSource + ",");
            builder.Append("" + model.InputDetailsSource + ",");
            builder.Append("" + model.BuildMoney + ",");
            builder.Append("" + model.CreateMan + ",");
            builder.Append("'" + model.NotesNum + "',");
            builder.Append("'" + model.CreateTime + "',");
            builder.Append("" + model.IsCheck + ",");
            builder.Append("" + model.CheckMan + ",");
            builder.Append("'" + model.CheckTime + "',");
            builder.Append("'" + model.Remark + "'");
            builder.Append(")");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public void Check(CompayAccountDetailsEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update T_CompayAccountDetails set ");
            builder.Append("CheckMan=" + model.CheckMan + ",");
            builder.Append("CheckTime='" + model.CheckTime + "',");
            builder.Append("IsCheck=" + model.IsCheck + "");
            builder.Append(" where DetailsId=" + model.DetailsId + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public void Delete(int DetailsId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete  from T_CompayAccountDetails ");
            builder.Append(" where DetailsId=" + DetailsId);
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public DataTable GetList(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_CompayAccountDetails ");
            if ((strWhere.Trim() != "") && (strWhere.ToLower().IndexOf("where") >= 0))
            {
                strWhere = strWhere.Replace("where", "");
                builder.Append(" where " + strWhere);
            }
            builder.Append(" order by DetailsId ");
            return DbHelperOledb.Query(this.dbname, builder.ToString());
        }

        public int GetMaxId(string swhere)
        {
            return DbHelperOledb.GetMaxID(this.dbname, "DetailsId", "T_CompayAccountDetails", swhere);
        }

        public CompayAccountDetailsEnt GetModel(int DetailsId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select DetailsId,ChainNum,DetailsType,OutDetailsSource,InputDetailsSource,BuildMoney,CreateMan,NotesNum,CreateTime,IsCheck,CheckMan,CheckTime,Remark from T_CompayAccountDetails ");
            builder.Append(" where DetailsId=" + DetailsId);
            CompayAccountDetailsEnt ent = new CompayAccountDetailsEnt();
            DataTable table = DbHelperOledb.Query(this.dbname, builder.ToString());
            ent.DetailsId = DetailsId;
            if (table.Rows.Count > 0)
            {
                if (table.Rows[0]["ChainNum"].ToString() != "")
                {
                    ent.ChainNum = int.Parse(table.Rows[0]["ChainNum"].ToString());
                }
                if (table.Rows[0]["DetailsType"].ToString() != "")
                {
                    ent.DetailsType = int.Parse(table.Rows[0]["DetailsType"].ToString());
                }
                if (table.Rows[0]["OutDetailsSource"].ToString() != "")
                {
                    ent.OutDetailsSource = int.Parse(table.Rows[0]["OutDetailsSource"].ToString());
                }
                if (table.Rows[0]["InputDetailsSource"].ToString() != "")
                {
                    ent.InputDetailsSource = int.Parse(table.Rows[0]["InputDetailsSource"].ToString());
                }
                if (table.Rows[0]["BuildMoney"].ToString() != "")
                {
                    ent.BuildMoney = decimal.Parse(table.Rows[0]["BuildMoney"].ToString());
                }
                if (table.Rows[0]["CreateMan"].ToString() != "")
                {
                    ent.CreateMan = int.Parse(table.Rows[0]["CreateMan"].ToString());
                }
                ent.NotesNum = table.Rows[0]["NotesNum"].ToString();
                if (table.Rows[0]["CreateTime"].ToString() != "")
                {
                    ent.CreateTime = DateTime.Parse(table.Rows[0]["CreateTime"].ToString());
                }
                if (table.Rows[0]["IsCheck"].ToString() != "")
                {
                    ent.IsCheck = int.Parse(table.Rows[0]["IsCheck"].ToString());
                }
                if (table.Rows[0]["CheckMan"].ToString() != "")
                {
                    ent.CheckMan = int.Parse(table.Rows[0]["CheckMan"].ToString());
                }
                if (table.Rows[0]["CheckTime"].ToString() != "")
                {
                    ent.CheckTime = DateTime.Parse(table.Rows[0]["CheckTime"].ToString());
                }
                ent.Remark = table.Rows[0]["Remark"].ToString();
                return ent;
            }
            return null;
        }

        public DataTable GetPageList(int PageSize, int PageIndex, string strWhere)
        {
            string orderString = "";
            int pageCount = 0;
            int recordCount = 0;
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_CompayAccountDetails ");
            return DbHelperOledb.ExecutePager(this.dbname, PageIndex, PageSize, "", builder.ToString(), strWhere, orderString, out pageCount, out recordCount, "DetailsId");
        }

        public void Update(CompayAccountDetailsEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update T_CompayAccountDetails set ");
            builder.Append("ChainNum=" + model.ChainNum + ",");
            builder.Append("DetailsType=" + model.DetailsType + ",");
            builder.Append("OutDetailsSource=" + model.OutDetailsSource + ",");
            builder.Append("InputDetailsSource=" + model.InputDetailsSource + ",");
            builder.Append("BuildMoney=" + model.BuildMoney + ",");
            builder.Append("CreateMan=" + model.CreateMan + ",");
            builder.Append("NotesNum='" + model.NotesNum + "',");
            builder.Append("CreateTime='" + model.CreateTime + "',");
            builder.Append("IsCheck=" + model.IsCheck + ",");
            builder.Append("CheckMan=" + model.CheckMan + ",");
            builder.Append("CheckTime='" + model.CheckTime + "',");
            builder.Append("Remark='" + model.Remark + "'");
            builder.Append(" where DetailsId=" + model.DetailsId + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }
    }
}

